<template>
  <div>
    <el-container>
    <el-header><heads/></el-header>
    <el-container>
      <el-aside width="200px"><left/></el-aside>
      <el-main style="height:400px;"> 
        <van-row>
          <van-uploader title="到处" style="width:50px;height:30px"/>&nbsp;&nbsp;&nbsp;&nbsp;
          <van-uploader :after-read="updalod" style="width:50px;height:50px"/>
          <van-search
            v-model="name"
            show-action
            placeholder="请输入搜索关键词"
            @search="getname"
          >
            <template #action>
              <div @click="getname">搜索</div>
            
            </template>
          </van-search>
            <van-row>
              <van-cell is-link @click="showPopup" >新增</van-cell>
              <van-popup v-model:show="show"  style="width:500px;height:500px" >

                <van-field v-model="name" label="组织名称" placeholder="请输入名称" />
                &nbsp;&nbsp;&nbsp;
                <van-radio-group v-model="type" direction="horizontal">
                  <van-radio name="1">企业</van-radio>
                  <van-radio name="2">部门</van-radio>
                </van-radio-group>
                <van-field v-model="set" label="组织缩写" placeholder="请输入编号" />
                <van-button @click="add">添加</van-button>
              </van-popup>
            </van-row>
          <companytree @changepid="getpid(pid)" />
        </van-row>
        <div>
        <div> 
          <gain/>

        </div>
            
        </div>
      </el-main>
    </el-container>
    </el-container>
  </div>   
</template>

<script>
import maxios from 'axios'
import heads from '../tt/heads.vue'
import left from '../tt/left.vue'
import gain from '../tt/gain.vue'
export default {
  components: {
    heads,
    left,
    gain

  }, 
  data(){
    return {
      pid:0,
      name:'',
      show: false,
      type:1,
      set:''
    }
  },  
  methods: {
  
    showPopup() {
      this.show = true;
    },
    updalod(file){
      console.log(file.file)
      let data=new FormData()
      data.append("file",file.file)
      maxios({
        method: "post", 
        url: "http://127.0.0.1:5000/upload",
      }).then(res=>{
        console.log(res)
      })

    },
    getname(){
      maxios({ 
        method: "get", 
        url: "http://127.0.0.1:5000/getname?name="+this.name,
        }).then(res=>{
          console.log(res)
        })
    },
    add(){

        if(localStorage.getItem('pid')){
          this.pid = localStorage.getItem('pid')
          print(this.pid)
          
        }
        let date = {'name': this.name,  'type':this.type,  'set':this.set, 'pid': this.pid}
        maxios({url:'http://127.0.0.1:5000/addname', method:'post', data:date}).then(res=>{
          console.log(res)
        })
        },
        
    getpid(id){

      alert(id)
    },
  },
}
</script>

<style>

</style>